#!/user/bin/env node

const log = console.log,
      http = require('http');

http.createServer((req,res)=>{
  log(`HTTP/ ${req.httpVersion} ${req.statusCode} ${req.statusMessage}`);
  log(req.headers);
  log('');

  log('host:',req.headers.host);
  log('user-agent:',req.headers['user-agent']);
  log('content-type:',req.headers['content-type']);
  let auth = req.headers.authorization;
  log('authorization:',auth);

  if(typeof(auth)!=='undefined'){
    auth = auth.split(' ');
    if(auth[0] === 'Basic'){
      let buf = new Buffer(auth[1],'base64');
      log('uaername & passwd:',buf.toString('utf8'));
    }
  }

  res.end('ok~');
}).listen(8080);
